<!-- 招聘管理 -->
<template>
  <div class="page-box h100 display-flex czbj">
    <p class="title-label mb10">招聘管理</p>
    <dxtable
      :dataJson="dataJson"
      :portUrl="portUrl"
      :formJson="formJson"
      :qx="qx"
      :czFun="czFun"
      czWidth="320"
      ref="databale"
    ></dxtable>
    <p class="z9 fz12">
      温馨提示：当面试管理，确认录用，该职位为合作中的状态，
      合作中的状态操作重新招聘或合作顺利，合作顺利 操作栏才会出现分成按钮  
      合作中的状态，点击完成 进入合作顺利的状态
    </p>
    <n-modal v-model:show="showModal" preset="card" class="dfsrtrtrt">
      <template #header>
        <div>重新招聘</div>
      </template>
      <div>
        <p>当前录用人</p>
        <div class="fsdfsdrtdsd mt20">
          <div class="">id：{{ usjeder.id }}</div>
          <div class="">姓名：{{ usjeder.name }}</div>
          <div class="">
            等级：{{ usjeder.dengji == 2 ? "VIP" : "普通用户" }}
          </div>
          <div class="">手机号：{{ usjeder.phone }}</div>
          <div class="">邮箱：{{ usjeder.email }}</div>
          <div class="">录用时间：{{ usjeder.lysj }}</div>
          <div class="">
            简历：<a :href="usjeder.jianli" class="sz ls" target="_blank"
              >点击查看</a
            >
          </div>
        </div>
        <div class="mt20">
          <n-input
            v-model:value="dfsfrtertert"
            rows="5"
            type="textarea"
            placeholder="请输入重新招聘理由"
          />
        </div>
      </div>
      <template #action>
        <div class="tr">
          <n-button type="info" @click="tijisdrtre" :loading="kdfssdf">
            提交
          </n-button>
          <n-button class="ml20" @click="showModal = false"> 取消 </n-button>
        </div>
      </template>
    </n-modal>




    <n-modal v-model:show="showModaler" preset="card" class="dfsrtrtrt">
      <template #header>
        <div>录取人员</div>
      </template>
      <div>
        <p>当前录用人</p>
        <div class="fsdfsdrtdsd mt20">
          <div class="">id：{{ usjeder.id }}</div>
          <div class="">姓名：{{ usjeder.name }}</div>
          <div class="">
            等级：{{ usjeder.dengji == 2 ? "VIP" : "普通用户" }}
          </div>
          <div class="">手机号：{{ usjeder.phone }}</div>
          <div class="">邮箱：{{ usjeder.email }}</div>
          <div class="">录用时间：{{ usjeder.lysj }}</div>
          <div class="">
            简历：<a :href="usjeder.jianli" class="sz ls" target="_blank"
              >点击查看</a
            >
          </div>
        </div>
      </div>
      <template #action>
        <div class="tr">
          <n-button class="ml20" @click="showModaler = false"> 关闭 </n-button>
        </div>
      </template>
    </n-modal>
  </div>
</template>
<script lang="ts" setup>
import { Options } from "@vicons/ionicons5";
import dxtable from "../../components/util/dxtable.vue";
import sort from "../../components/util/sort.vue";
import { dxget, dxpost, dialog, transferTimeYMDHm } from "../../util/index";
import { NButton, NImage, NTag,NSwitch  } from "naive-ui";
import { h, ref, reactive } from "vue";
import ypzfc from "./components/ypzfc.vue"
import zpzher from "./components/zpzher.vue"
const databale = ref();
const showModal = ref(false);
const usjeder = ref(null);
const showModaler= ref(false)
const dfsfrtertert = ref();
const initeer = () => {
  databale.value.initDataExpose();
};
const kdfssdf = ref(false);

const hjssdf = [
  {
    label: "正常",
    value: "1",
  },
  {
    label: "合作中",
    value: "2",
  },
  {
    label: "停止招聘",
    value: "3",
  },
  {
    label: "合作顺利",
    value: "4",
  },
];
const dsfdsfa = [
  {
    label: "未分成",
    value: "1",
  },
  {
    label: "已分成",
    value: "2",
  },
];

let dataJson = [
  {
    title: "名称",
    key: "name",
    width: "",
    search: true,
    istable: true,
    required: false,
  },
  {
    title: "招聘价格",
    key: "zpjiage",
    width: "",
    search: false,
    istable: true,
    required: false,
  },
  {
    title: "试用期价格",
    key: "syqjg",
    width: "",
    search: false,
    istable: true,
    required: false,
  },
  {
    title: "薪资待遇",
    key: "xzdy",
    width: "",
    search: false,
    istable: true,
    required: false,
  },
  {
    title: "雇主",
    key: "guid",
    type: "select",
    options: [],
    width: "300",
    search: true,
    istable: true,
    required: false,
    render: (row) => {
      try {
        return dataJson[4].options.filter((a) => a.value == row.guid)[0].label;
      } catch (e) {
        return "--";
      }
    },
  }, {
    title: "简历可看性",
    key: "jlkk",
    render: (row) => {
        let jdfds = 1;
      return [
        h(NSwitch, {
          "default-value": row.jlkk == 1 ? true : false,
          "on-update:value": async (e) => {
           
            if (row.jlkk == 1) {
              jdfds = 2;
            }
            await dxpost(portUrl, { id: row.id, jlkk: jdfds }, "put");
          },
        })
      ];
    },
  },
  {
    title: "工作地点",
    width: "",
    search: false,
    istable: true,
    required: false,
    render: (row) => {
      return row.sheng + "-" + row.shi;
    },
  },
  {
    title: "录取人员",
    width: "",
    render: (row) => {
      if(row.uname){
        return h("span",{class:"ls sz",onClick:async()=>{
        
          const { data }:any = await dxget("jyc/jycadmin/getjsdfd", {
                uid: row.ypzid,
                id: row.id,
              });
              showModaler.value = true;
              usjeder.value = data;
        }},row.uname)
      }else{
        return '--'
      }
    },
  },
  


  {
    title: "招聘状态",
    width: "",
    key: "zpzt",
    search: true,
    type: "select",
    options: [
      {
        label: "全部",
        value: "",
      },
      ...hjssdf,
    ],
    istable: true,
    required: false,
    render: (row) => {
      // return hjssdf.filter(a=>a.value==row.zpzt)[0].label
      if (row.zpzt == 1) {
        return h("span", { class: "ls" }, "正常");
      }
      if (row.zpzt == 2) {
        return h("span", { class: "ye" }, "合作中");
      }
      if (row.zpzt == 3) {
        return h("span", { class: "red" }, "停止招聘");
      }
      if (row.zpzt == 4) {
        return h("span", { class: "z3" }, "合作顺利");
      }
    },
  },
  {
    title: "应聘推广员分成状态",
    width: "",
    key: "isfc",
    search: true,
    type: "select",
    options: [
      {
        label: "全部",
        value: "",
      },
      ...dsfdsfa,
    ],
    istable: true,
    required: false,
    render: (row) => {
      if (row.zpzt != 4) {
        return '--';
      }
      if (row.isfc == 1) {
        return h("span", { class: "ls" }, "未分成");
      }
      if (row.isfc == 2) {
        return h("span", { class: "z3" }, "已分成");
      }
    },
  }, {
    title: "雇主推广员分成状态",
    width: "",
    key: "zpfc",
    search: true,
    type: "select",
    options: [
      {
        label: "全部",
        value: "",
      },
      ...dsfdsfa,
    ],
    istable: true,
    required: false,
    render: (row) => {
      if (row.zpfc == 1) {
        return h("span", { class: "ls" }, "未分成");
      }
      if (row.zpfc == 2) {
        return h("span", { class: "z3" }, "已分成");
      }
    },
  },
  {
    title: "排序",
    width: 100,
    render: (row) => {
      row.sjk = "jyc"; //数据库
      row.databaseName = "zhaoping"; //表名
      return h(sort, {
        row,
        onCallBack: () => {
          initeer();
        },
      });
    },
  },
  {
    title: "添加时间",
    key: "addTime",
    width: 150,
  },
];

const qx = {
  DeletePermissionID: "jyczhaopingdel", //删除
  EditPermissionIdentifier: "jyczhaopingbj", // 编辑
  NewPermissionIdentifier: "jyczhaopingxz", // 新建
  ViewPermissionID: "jyczhaopingck", // 查看
};
const portUrl = "jyc/zhaoping/zhaoping";

let formJson = reactive([
  {
    title: "名称",
    type: "input",
    val: "",
    icon: "dx-shurukuang",
    span: 24,
    key: "name",
    width: "",
    search: false,
    istable: true,
    required: true,
  },
  {
    title: "招聘价格",
    type: "number",
    val: "",
    icon: "dx-Field-number",
    span: 12,
    key: "zpjiage",
    width: "",
    search: false,
    istable: true,
    required: true,
  },
  {
    title: "试用期价格",
    type: "input",
    val: "",
    icon: "dx-Field-number",
    span: 12,
    key: "syqjg",
    width: "",
    search: false,
    istable: true,
    required: false,
  },
  {
    title: "薪资待遇",
    type: "input",
    val: "",
    icon: "dx-Field-number",
    span: 12,
    key: "xzdy",
    width: "",
    search: false,
    istable: true,
    required: true,
  },
  {
    title: "雇主uid",
    type: "select",
    options: [],
    val: "",
    icon: "dx-shurukuang",
    span: 24,
    key: "guid",
    width: "",
    search: false,
    istable: true,
  },
  {
    title: "工作地点",
    type: "shengshi",
    val: "",
    icon: "dx-shurukuang",
    span: 12,
    key: "",
    width: "",
    search: false,
    istable: true,
    required: false,
  },
  {
    title: "详情",
    type: "fwb",
    val: "",
    icon: "dx-m-fuwenben",
    span: 24,
    key: "xq",
    width: "",
    search: false,
    istable: true,
    required: false,
  },
]);
let jdfds = ref(false);
const czFun = {
  fun: (row) => {
    let jkfdsfs = [];
    if (row.zpzt == 4) {
      jkfdsfs = [
        h(
          ypzfc,
          {
            dxdata: row,
            onCallback:()=>{
              initeer()
            }
          }
        )
        
      ];
    } else if (row.zpzt == 2) {
      jkfdsfs = [
        h(
          NButton,
          {
            type: "info",
            quaternary: true,
            loading: jdfds.value,
            onClick: async (e) => {
              // let statics: any = await dialog("是否重新招聘");
              // if (statics == 1) {   }
              const { data } = await dxget("jyc/jycadmin/getjsdfd", {
                uid: row.ypzid,
                id: row.id,
              });
              showModal.value = true;
              usjeder.value = data;
            },
          },
          "重新招聘"
        ),
        h(
          NButton,
          {
            type: "info",
            quaternary: true,
            loading: jdfds.value,
            onClick: async (e) => {
              let statics: any = await dialog("是否确认该职位顺利完成");
              if (statics == 1) {
                const { data } = await dxget("jyc/jycadmin/getjsdfd", {
                  uid: row.ypzid,
                  id: row.id,
                });

                await dxpost(
                  "jyc/miansi/miansi",
                  {
                    id: data.msid,
                    wcsj: transferTimeYMDHm(),
                    luyong: 4,
                  },
                  "put"
                );

                await dxpost(portUrl, { id: row.id, zpzt: 4 }, "put");
                initeer();
              }
            },
          },
          "完成"
        ),
      ];
    } else {
      jkfdsfs = [
        h(
          NButton,
          {
            type: "info",
            quaternary: true,
            loading: jdfds.value,
            onClick: async (e) => {
              jdfds.value = true;
              await dxpost(
                portUrl,
                { id: row.id, zpzt: row.zpzt == 3 ? 1 : 3 },
                "put"
              );
              jdfds.value = false;
              initeer();
            },
          },
          row.zpzt == 3 ? "重新招聘" : "停止招聘"
        ),
      ];
    }
    return [...jkfdsfs,h(
          zpzher,
          {
            dxdata: row,
            onCallback:()=>{
              initeer()
            }
          },
        ),];
  },
};

// 获取字典内容
// const xtgxxmfl = async () => {
//   const { data }: any = await dxget("dxgjAdmin/getzd", { name: 'xtgxxmfl' })
//   dataJson[2].options = [
//     {
//       label: "全部",
//       value: ""
//     },
//     ...data
//   ]
//   formJson[2].options = data
//   xmlxSelect.value = data
//   console.log(data);
// }
// xtgxxmfl()

const getuserlistIdname = async () => {
  const { data }: any = await dxget("jyc/api/getuserlistIdname");
  dataJson[4].options = [
    {
      label: "全部",
      value: "",
    },
    ...data,
  ];
  formJson[4].options = data;
  console.log(data);
};
getuserlistIdname();
const tijisdrtre = async () => {
  if (!dfsfrtertert.value) {
    window.$message.error("重新招聘理由不能为空");
    return;
  }
  kdfssdf.value = true;
  await dxpost(
    "jyc/miansi/miansi",
    {
      id: usjeder.value.msid,
      cxzpbz: dfsfrtertert.value,
      cxzpsj: transferTimeYMDHm(),
      luyong: 3,
    },
    "put"
  );
  await dxpost(
    portUrl,
    {
      id: usjeder.value.zwid,
      zpzt: 1,
      ypzid: 0,
    },
    "put"
  );
  try {
    await dxpost("jyc/jycadmin/putongrizhi", {
      id: usjeder.value.id,
      name: usjeder.value.zwname,
      beizhu: "很抱歉，您已被解雇了，该职位重新录用了",
      czlx: "取消录用",
    });
  } catch (e) {}
  kdfssdf.value = false;
  showModal.value = false;
  initeer();
};
</script>
<style scoped></style>
